﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PushOut : MonoBehaviour {

	private List< Collider > IgnoredColliders = new List< Collider > ();
	public float forceMagnitude = 1.0f;
	public float rangeMod = 1.0f;

	public GrowAndDestroy grow;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	public void AddIgnoreCollider( Collider collider )
	{
		IgnoredColliders.Add (collider);
	}

	void OnTriggerStay(Collider other) {

		if (IgnoredColliders.Contains (other))
			return;

		if ( other.rigidbody )
		{
			Vector3 diff = other.transform.position - transform.position;
			diff.y = 0;
			float range = grow.GetScale() * rangeMod;

			if(diff.magnitude < range && diff.magnitude > 0.01f)
			{
				diff.Normalize();
				other.rigidbody.AddForce( diff * forceMagnitude );
			}
		}
	}

	void OnDrawGizmos()
	{
		Gizmos.DrawWireSphere(transform.position, grow.GetScale() * rangeMod );
	}
}
